﻿<Window x:Class="ConvertSourceToHtml.SettingsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ConvertSourceToHtml"
        xmlns:winforms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        xmlns:cc="clr-namespace:ConvertSourceToHtmlCustomControls;assembly=ConvertSourceToHtmlCustomControls"
        xmlns:props="clr-namespace:ConvertSourceToHtml.Properties"
        Title="Settings" WindowStyle="None" AllowsTransparency="True" Background="Transparent"
        SizeToContent="WidthAndHeight" WindowStartupLocation="CenterOwner"
        KeyDown="Window_KeyDown">
    <Window.Resources>
        <Style TargetType="GroupBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="GroupBox">
                        <Grid>
                            <Border Margin="0, 12, 0, 0" CornerRadius="7" Background="#C4A385">
                                <ContentPresenter Margin="10, 20, 10, 10" />
                            </Border>
                            <Border Background="#7F5E43" HorizontalAlignment="Left"
                                    VerticalAlignment="Top" Margin="10, 0, 0, 0" CornerRadius="7">
                                <ContentPresenter ContentSource="Header" Margin="7, 3" TextElement.Foreground="White"
                                                  TextElement.FontSize="13"/>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style TargetType="TextBox">
            <Setter Property="Height" Value="20" />
            <Setter Property="Padding" Value="0, 0, 0, 2" />
        </Style>
        
        <local:FractionToPercentageConverter x:Key="fractionToPercentageConverter" />
    </Window.Resources>
    
    <Border Name="windowBackground" Width="300" Height="Auto" CornerRadius="40, 0, 40, 0" Background="#CCFFE4C4"
            MouseLeftButtonDown="windowBackground_MouseLeftButtonDown">
        <StackPanel Margin="16, 23, 15, 16">
            <GroupBox Header="Line Numbering" Margin="0, 0, 0, 20">
                <StackPanel>
                    <CheckBox Name="numberLinesCheckBox"
                              IsChecked="{Binding Source={x:Static props:Settings.Default}, Path=NumberLines,
                                          Mode=TwoWay, UpdateSourceTrigger=Explicit}">
                        Number lines
                    </CheckBox>
                    <StackPanel Orientation="Horizontal" Margin="0, 3, 0, 0">
                        <Label>Number lines from </Label>
                        <TextBox Name="numberingStartTextBox" Width="30"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=NumberLinesFrom,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                                 IsEnabled="{Binding ElementName=numberLinesCheckBox, Path=IsChecked}" />
                    </StackPanel>
                </StackPanel>
            </GroupBox>
            
            <GroupBox Header="Styles" Margin="0, 0, 0, 15">
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Label Width="70">Font family </Label>
                        <TextBox Name="fontFamilyTextBox" Width="100"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=FontList,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0, 3, 0, 0">
                        <Label Width="70">Font size </Label>
                        <TextBox Name="fontSizeTextBox" Width="30"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=FontSize,
                                        Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0, 3, 0, 0">
                        <Label Width="110">Background color</Label>
                        <Label>R</Label>
                        <TextBox Name="backgroundColorRTextBox" Width="28"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=BackgroundColorR,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
                        <Label>G</Label>
                        <TextBox Name="backgroundColorGTextBox" Width="28"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=BackgroundColorG,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
                        <Label>B</Label>
                        <TextBox Name="backgroundColorBTextBox" Width="28"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=BackgroundColorB,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0, 3, 0, 0">
                        <Label Width="110">Line number color</Label>
                        <Label>R</Label>
                        <TextBox Name="lineNumberColorRTextBox" Width="28"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=LineNumberColorR,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                                 IsEnabled="{Binding ElementName=numberLinesCheckBox, Path=IsChecked}" />
                        <Label>G</Label>
                        <TextBox Name="lineNumberColorGTextBox" Width="28"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=LineNumberColorG,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                                 IsEnabled="{Binding ElementName=numberLinesCheckBox, Path=IsChecked}" />
                        <Label>B</Label>
                        <TextBox Name="lineNumberColorBTextBox"
                                 Text="{Binding Source={x:Static props:Settings.Default}, Path=LineNumberColorB,
                                                Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                                 Width="28" IsEnabled="{Binding ElementName=numberLinesCheckBox, Path=IsChecked}" />
                    </StackPanel>
                    <CheckBox Name="alternateBackgroundCheckBox" Margin="0, 3, 0, 0"
                              IsChecked="{Binding Source={x:Static props:Settings.Default}, Path=AlternateBackgroundColors,
                                                  Mode=TwoWay, UpdateSourceTrigger=Explicit}">
                        Alternate background color
                    </CheckBox>
                    <StackPanel Orientation="Horizontal" Margin="0, 3, 0, 0">
                        <Label>Variation percentage </Label>
                        <cc:NumericUpDown Name="variationPercentageNumericUpDown" Minimum="-30" Maximum="30" Margin="0, 0, 3, 0"
                                          Value="{Binding Source={x:Static props:Settings.Default},
                                                          Path=AlternateBackgroundColorAdjustment,
                                                          Mode=TwoWay, UpdateSourceTrigger=Explicit,
                                                          Converter={StaticResource fractionToPercentageConverter}}"
                                          IsEnabled="{Binding ElementName=alternateBackgroundCheckBox, Path=IsChecked}"/>
                        <TextBlock VerticalAlignment="Center">%</TextBlock>
                    </StackPanel>
                </StackPanel>
            </GroupBox>
            
            <StackPanel Orientation="Horizontal">
                <Border Style="{StaticResource stylishButtonBorder}" CornerRadius="10">
                    <Border Style="{StaticResource stylishButton}" CornerRadius="9" MouseLeftButtonUp="saveButton_MouseLeftButtonUp">
                        <TextBlock Margin="8, 3, 8, 5" Style="{StaticResource stylishButtonText}" FontSize="13">
                            Save Settings
                        </TextBlock>
                    </Border>
                </Border>
                <Border Style="{StaticResource stylishButtonBorder}" Margin="7, 0, 0, 0" CornerRadius="10">
                    <Border Style="{StaticResource stylishButton}" CornerRadius="9" MouseLeftButtonUp="cancelButton_MouseLeftButtonUp">
                        <TextBlock Margin="8, 3, 8, 5" Style="{StaticResource stylishButtonText}" FontSize="13">
                            Cancel
                        </TextBlock>
                    </Border>
                </Border>
            </StackPanel>
        </StackPanel>
    </Border>
</Window>
